// cashmachine2.txt
// by Thralni
// version 1.0.0

// WARNING: this script reserves the flag 50,0!

// Many thanks to Kelandon, who let me copy a part of his own scirpt "t2raiser.txt," part of the HLPM.

// Copy the below variables to the variables section of your town script.

variables;

int c,choice;
short amount_to_withdraw;
short amount_to_pay;
short which_state;
short what_num;

// Copy the section below to the appropriate town script,  and replace the X's at the states with state numbers appropriate for your script.

beginstate x; // Replace your own state number with the "x"
reset_dialog();
add_dialog_str(0,"This control panel has a small screen and some buttons next to it. its not very large. on the screen, a small message is displayed:",0);
add_dialog_str(1,"_Welcome to Banka Riverrod. What would you like to do?_ Two options are listed below. The third one isn't on the screen, it is there to give you the option not to do anything.",0);
add_dialog_choice(0,"Withdraw");
add_dialog_choice(1,"Deposit");
add_dialog_choice(2,"Do nothing");
choice = run_dialog(0);
	
	if (choice == 1) {
			c = coins_amount();
			print_num(c);
			
			message_dialog("Down in the text area you can see how many coins you have. It says _debug value,_ followed by your amount of coins. Just pretend it says _amount of coins,_ will you?","Click OK to proceed, please.");
			message_dialog("In the next dialog box you'll have to define an mount of money. DON'T ask for more than 100 coins per time!","Click OK to proceed, please.");
			
			get_text_response("Amount to withdraw:");
			
			which_state = x + 2; // enter the state number you used before (x), but now count 2 up, so you get x + 2
			set_state_continue(x + 1); // enter the state number you used before (x), but now count 1 up, so you get x + 1
			}
	
	if (choice == 2) {
			c = coins_amount();
			print_num(c);
			
			message_dialog("Down in the text area you can see how many coins you have. It says _debug value,_ followed by your amount of coins. Just pretend it says _amount of coins,_ will you?","Click OK to proceed, please.");
			message_dialog("In the next dialog box you'll have to define an mount of money. DON'T ask for more than 100 coins per time!","Click OK to proceed, please.");
			
			which_state = x + 3; // enter the state number you used before (x), but now count 3 up, so you get x + 3
			
			get_text_response("Amount to deposit:");
			set_state_continue(x + 1); // enter the state number you used before (x), but now count 1 up, so you get x + 1
			}
break;

beginstate x + 1;
what_num = 0;

	check_text_response_match("1");
	if (got_text_match())
		what_num = 1;
	check_text_response_match("2");
	if (got_text_match())
		what_num = 2;
	check_text_response_match("3");
	if (got_text_match())
		what_num = 3;
	check_text_response_match("4");
	if (got_text_match())
		what_num = 4;
	check_text_response_match("5");
	if (got_text_match())
		what_num = 5;
	check_text_response_match("6");
	if (got_text_match())
		what_num = 6;
	check_text_response_match("7");
	if (got_text_match())
		what_num = 7;
	check_text_response_match("8");
	if (got_text_match())
		what_num = 8;
	check_text_response_match("9");
	if (got_text_match())
		what_num = 9;
	check_text_response_match("10");
	if (got_text_match())
		what_num = 10;
	check_text_response_match("11");
	if (got_text_match())
		what_num = 11;
	check_text_response_match("12");
	if (got_text_match())
		what_num = 12;
	check_text_response_match("13");
	if (got_text_match())
		what_num = 13;
	check_text_response_match("14");
	if (got_text_match())
		what_num = 14;
	check_text_response_match("15");
	if (got_text_match())
		what_num = 15;
	check_text_response_match("16");
	if (got_text_match())
		what_num = 16;
	check_text_response_match("17");
	if (got_text_match())
		what_num = 17;
	check_text_response_match("18");
	if (got_text_match())
		what_num = 18;
	check_text_response_match("19");
	if (got_text_match())
		what_num = 19;
	check_text_response_match("20");
	if (got_text_match())
		what_num = 20;
	check_text_response_match("21");
	if (got_text_match())
		what_num = 21;
	check_text_response_match("22");
	if (got_text_match())
		what_num = 22;
	check_text_response_match("23");
	if (got_text_match())
		what_num = 23;
	check_text_response_match("24");
	if (got_text_match())
		what_num = 24;
	check_text_response_match("25");
	if (got_text_match())
		what_num = 25;
	check_text_response_match("26");
	if (got_text_match())
		what_num = 26;
	check_text_response_match("27");
	if (got_text_match())
		what_num = 27;
	check_text_response_match("28");
	if (got_text_match())
		what_num = 28;
	check_text_response_match("29");
	if (got_text_match())
		what_num = 29;
	check_text_response_match("30");
	if (got_text_match())
		what_num = 30;
	check_text_response_match("31");
	if (got_text_match())
		what_num = 31;
	check_text_response_match("32");
	if (got_text_match())
		what_num = 32;
	check_text_response_match("33");
	if (got_text_match())
		what_num = 33;
	check_text_response_match("34");
	if (got_text_match())
		what_num = 34;
	check_text_response_match("35");
	if (got_text_match())
		what_num = 35;
	check_text_response_match("36");
	if (got_text_match())
		what_num = 36;
	check_text_response_match("37");
	if (got_text_match())
		what_num = 37;
	check_text_response_match("38");
	if (got_text_match())
		what_num = 38;
	check_text_response_match("39");
	if (got_text_match())
		what_num = 39;
	check_text_response_match("40");
	if (got_text_match())
		what_num = 40;
	check_text_response_match("41");
	if (got_text_match())
		what_num = 41;
	check_text_response_match("42");
	if (got_text_match())
		what_num = 42;
	check_text_response_match("43");
	if (got_text_match())
		what_num = 43;
	check_text_response_match("44");
	if (got_text_match())
		what_num = 44;
	check_text_response_match("45");
	if (got_text_match())
		what_num = 45;
	check_text_response_match("46");
	if (got_text_match())
		what_num = 46;
	check_text_response_match("47");
	if (got_text_match())
		what_num = 47;
	check_text_response_match("48");
	if (got_text_match())
		what_num = 48;
	check_text_response_match("49");
	if (got_text_match())
		what_num = 49;
	check_text_response_match("50");
	if (got_text_match())
		what_num = 50;
	check_text_response_match("51");
	if (got_text_match())
		what_num = 51;
	check_text_response_match("52");
	if (got_text_match())
		what_num = 52;
	check_text_response_match("53");
	if (got_text_match())
		what_num = 53;
	check_text_response_match("54");
	if (got_text_match())
		what_num = 54;
	check_text_response_match("55");
	if (got_text_match())
		what_num = 55;
	check_text_response_match("56");
	if (got_text_match())
		what_num = 56;
	check_text_response_match("57");
	if (got_text_match())
		what_num = 57;
	check_text_response_match("58");
	if (got_text_match())
		what_num = 58;
	check_text_response_match("59");
	if (got_text_match())
		what_num = 59;
	check_text_response_match("60");
	if (got_text_match())
		what_num = 60;
	check_text_response_match("61");
	if (got_text_match())
		what_num = 61;
	check_text_response_match("62");
	if (got_text_match())
		what_num = 62;
	check_text_response_match("63");
	if (got_text_match())
		what_num = 63;
	check_text_response_match("64");
	if (got_text_match())
		what_num = 64;
	check_text_response_match("65");
	if (got_text_match())
		what_num = 65;
	check_text_response_match("66");
	if (got_text_match())
		what_num = 66;
	check_text_response_match("67");
	if (got_text_match())
		what_num = 67;
	check_text_response_match("68");
	if (got_text_match())
		what_num = 68;
	check_text_response_match("69");
	if (got_text_match())
		what_num = 69;
	check_text_response_match("70");
	if (got_text_match())
		what_num = 70;
	check_text_response_match("71");
	if (got_text_match())
		what_num = 71;
	check_text_response_match("72");
	if (got_text_match())
		what_num = 72;
	check_text_response_match("73");
	if (got_text_match())
		what_num = 73;
	check_text_response_match("74");
	if (got_text_match())
		what_num = 74;
	check_text_response_match("75");
	if (got_text_match())
		what_num = 75;
	check_text_response_match("76");
	if (got_text_match())
		what_num = 76;
	check_text_response_match("77");
	if (got_text_match())
		what_num = 77;
	check_text_response_match("78");
	if (got_text_match())
		what_num = 78;
	check_text_response_match("79");
	if (got_text_match())
		what_num = 79;
	check_text_response_match("80");
	if (got_text_match())
		what_num = 80;
	check_text_response_match("81");
	if (got_text_match())
		what_num = 81;
	check_text_response_match("82");
	if (got_text_match())
		what_num = 82;
	check_text_response_match("83");
	if (got_text_match())
		what_num = 83;
	check_text_response_match("84");
	if (got_text_match())
		what_num = 84;
	check_text_response_match("85");
	if (got_text_match())
		what_num = 85;
	check_text_response_match("86");
	if (got_text_match())
		what_num = 86;
	check_text_response_match("87");
	if (got_text_match())
		what_num = 87;
	check_text_response_match("88");
	if (got_text_match())
		what_num = 88;
	check_text_response_match("89");
	if (got_text_match())
		what_num = 89;
	check_text_response_match("90");
	if (got_text_match())
		what_num = 90;
	check_text_response_match("91");
	if (got_text_match())
		what_num = 91;
	check_text_response_match("92");
	if (got_text_match())
		what_num = 92;
	check_text_response_match("93");
	if (got_text_match())
		what_num = 93;
	check_text_response_match("94");
	if (got_text_match())
		what_num = 94;
	check_text_response_match("95");
	if (got_text_match())
		what_num = 95;
	check_text_response_match("96");
	if (got_text_match())
		what_num = 96;
	check_text_response_match("97");
	if (got_text_match())
		what_num = 97;
	check_text_response_match("98");
	if (got_text_match())
		what_num = 98;
	check_text_response_match("99");
	if (got_text_match())
		what_num = 99;
	check_text_response_match("100");
	if (got_text_match())
		what_num = 100;
		
	// Make sure the player actually entered something correct. If not, end.

	if (what_num == 0)
		{message_dialog("A light flickers above the screen, saying the following:","_That wasn't a value between 1 and 100. Transaction cancelled._");
		end();
		}

	set_state_continue(which_state);
break;

beginstate x + 2; // enter the state number you used before (x), but now count 2 up, so you get x + 2
			amount_to_withdraw = what_num;
			
			if (get_flag(50,0) >= amount_to_withdraw) {
					change_coins(amount_to_withdraw);
					
					inc_flag(50,0,(what_num - (2 * what_num)));
					
					message_dialog("A small drawer appears, filled with money. You take the money out, and it closes.","");
					
					message_dialog("_You have withdrawn an amount of money. Thanks for coming to the Banka Riverrod._","Your new amount of money is shown at the bottom of the playing screen.");
				
					c = coins_amount();
					print_num(c);
					end();
					}
			
			if (get_flag(50,0) < amount_to_withdraw) {
					message_dialog("You don't have such a big sum of money on your bank account. Transaction cancelled.","");
					end();
					}
break;

beginstate x + 3;  // enter the state number you used before (x), but now count 3 up, so you get x + 3
			amount_to_pay = (what_num - (2 * what_num));
			
			if (c >= amount_to_pay) {
					change_coins(amount_to_pay);
					
					inc_flag(50,0,what_num);
					
					message_dialog("A small drawer appears, in which you put your money. It closes.","");
					
					message_dialog("_You have deposited an amount of money. Thanks for coming to the Banka Riverrod._","Your new amount of money is shown at the bottom of the playing screen.");
					
					c = coins_amount();
					print_num(c);
					
					end();
					}
			
			if (c < amount_to_pay) {
					message_dialog("A small drawer opens, in which you put your money. It closes. However, it opens almost immediately. You look at the red flashing screen:","That is not the right sum. Transaction cancelled.");
					end();
					}
break;